using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace JVIT.TimeSheet.GUI
{
    public static class Prompt
    {
        public static string ShowDialog(string text, string caption)
        {
            Form prompt = new Form();
            prompt.ShowIcon = false;
            prompt.ShowInTaskbar = false;
            prompt.Width = 430;
            prompt.Height = 130;
            prompt.Text = caption;
            prompt.MaximizeBox = false;
            prompt.MinimizeBox = false;
            prompt.ControlBox = false;
            prompt.FormBorderStyle = FormBorderStyle.FixedToolWindow;
            prompt.StartPosition = FormStartPosition.CenterParent;
            prompt.SizeGripStyle = SizeGripStyle.Hide;
            Label textLabel = new Label() { Left = 10, Top = 10, Width = 400, Text = text };
            TextBox textBox = new TextBox() { Left = 10, Top = 35, Width = 400, Name = "TextBox" };
            Button confirmation = new Button() { Text = "Ok", Left = 10, Width = 100, Top = 65 };
            Button cancel = new Button() { Text = "Cancel", Left = 120, Width = 100, Top = 65 };
            confirmation.Click += (sender, e) => { prompt.Close(); };
            cancel.Click += (sender, e) => { textBox.Text = ""; prompt.Close(); };
            prompt.Load += (sender, e) => { textBox.Select(); };
            prompt.AcceptButton = confirmation;
            prompt.CancelButton = cancel;
            //textBox.KeyUp += new KeyEventHandler(textBox_KeyUp);
            prompt.Controls.Add(confirmation);
            prompt.Controls.Add(cancel);
            prompt.Controls.Add(textLabel);
            prompt.Controls.Add(textBox);
            prompt.ShowDialog();
            return textBox.Text;
        }

        //static void textBox_KeyUp(object sender, KeyEventArgs e)
        //{
        //    if (e.KeyCode == Keys.Enter)
        //    {
        //        ((Form)((TextBox)sender).Parent).Close();
        //    }
        //    if (e.KeyCode == Keys.Escape)
        //    {
        //        Form form = ((Form)((TextBox)sender).Parent);
        //        TextBox textBox = form.Controls.Find("TextBox", true).FirstOrDefault() as TextBox;
        //        textBox.Text = "";
        //        form.Close();
        //    }
        //}
    }
}
